package com.reebake.ideal.storage.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.storage.entity.FileDetail;
import com.reebake.ideal.storage.service.FileDetailService;
import com.reebake.ideal.storage.vo.FileDetailQueryParamVO;
import com.reebake.ideal.storage.vo.FileDetailVO;

 /**
 * 文件记录控制层
 */
@Tag(name = "文件记录对象功能接口")
@RestController
@RequestMapping("/file/detail")
public class FileDetailController {
    @Autowired
    private FileDetailService fileDetailService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<FileDetailVO> page(@RequestBody FileDetailQueryParamVO queryParam) {
        LambdaQueryWrapper<FileDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getOriginalFilename()), FileDetail::getOriginalFilename, queryParam.getOriginalFilename());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getFilename()), FileDetail::getFilename, queryParam.getFilename());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getPath()), FileDetail::getPath, queryParam.getPath());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getPlatform()), FileDetail::getPlatform, queryParam.getPlatform());
        
        queryParam = fileDetailService.page(queryParam, queryWrapper);
        
        return queryParam.to(FileDetailVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param fileDetail 实例对象
     */
    @Operation(summary = "保存或更新数据")
    @PostMapping("save")
    public void save(@RequestBody FileDetailVO fileDetail) {
        fileDetailService.saveOrUpdate(BeanUtil.copyProperties(fileDetail, FileDetail.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param fileDetailIds 主键
     */
    @Operation(summary = "通过主键批量删除")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> fileDetailIds) {
        fileDetailService.removeByIds(fileDetailIds);
    }
}